@(project: String, task: String)

@import org.silkframework.workspace.User
@import org.silkframework.workspace.activity.workflow.Workflow

@workflowTask = @{ User().workspace.project(project).tasks[Workflow].find(_.id == task) }

@widgets.dialog(title = "Workflow Task") {
  @if(task.isEmpty) {
    <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
      <input class="mdl-textfield__input" type="text" id="workflow_name" name="workflow_name"/>
      <label class="mdl-textfield__label" for="workflow_name">Name</label>
    </div>
  }
}

<script type="text/javascript">
  function submit() {
    var values = {
      name: @if(!task.isEmpty) {'@task'} else {$("input[name='workflow_name']").val()},
    };

    if(values.name.length === 0) {
      alert("Task name is empty.");
      return;
    }

    $.ajax({
      type: 'PUT',
      url: '@config.baseUrl/workflow/workflows/@project/' + values.name,
      contentType: 'text/xml',
      processData: false,
      data: '<Workflow id="' + values.name + '"></Workflow>',
      success: function(data) {
        closeDialog();
        reloadWorkspace();
      },
      error: function(request) {
        alert(request.responseText);
      }
    });
  }
</script>